// Implementation of the ClientSocket class

#include "ClientSocket.h"
#include "SocketException.h"

ClientSocket::ClientSocket(std::string host, int port) {
    if (!MySocket::create()) {
        throw SocketException("Could not create client socket.");
    }

    if (!MySocket::connect(host, port)) {
        cout <<"Conectando:...: "<< host.c_str() <<" : "<< port << endl;
        throw SocketException("Could not bind to port.");
    }

}

const ClientSocket& ClientSocket::operator <<(const std::string& s) const {
    if (!MySocket::send(s)) {
        throw SocketException("Could not write to socket.");
    }

    return *this;

}

const ClientSocket& ClientSocket::operator >>(std::string& s) const {
    if (!MySocket::recv(s)) {
        throw SocketException("Could not read from socket.");
    }

    return *this;
}
